<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }

        html {
            height: 100%;
        }

        body {
            background: url('./imgs/weather-bg.webp') no-repeat center/cover;
            height: 100%;
            /* background: linear-gradient(rgb(66, 80, 170), rgb(191, 137, 190)) no-repeat center/cover; */
        }

        .w {
            width: 1000px;
            margin: 10px auto;
        }

        .shadow {
            padding: 10px;
            box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
        }

        .form {
            background-color: rgba(255, 255, 255, 0.2);
            border-radius: 4px;
        }

        .form-group {
            display: flex;
        }

        .form-group input[type="text"] {
            width: 50%;
            height: 36px;
            padding-left: 10px;
            border: 1px solid #CCC;
            outline: none;
            border-radius: 4px 0 0 4px;
        }

        button {
            background-color: #fff;
            padding: 8px;
            border: 1px solid #CCC;
            cursor: pointer;
            border-radius: 0 4px 4px 0;
        }

        .list {

            display: flex;
        }

        .col {
            flex: 1;
            padding: 10px;
            text-align: center;
            cursor: pointer;
            color: #fff;
        }

        .col:hover {
            border-radius: 4px;
            background: linear-gradient(to bottom, rgba(255, 255, 255, .2), rgba(0, 0, 0, .4));

        }

        .col>div {
            display: flex;
            margin: 20px 0;
            align-items: center;
            justify-content: center;
        }

        .col>div>img {
            margin-right: 10px;
            width: 20px;
            height: 20px;
        }


        .title {
            font-weight: 700;
        }

        .today {
            color: #fff;
            padding: 10px;
            border-radius: 4px;
        }
    </style>
</head>

<body>

    <form action="#" class="form w shadow">
        <div class="form-group">
            <input type="text" placeholder="请输入要查询的城市名称" class="form-control">
            <button>立即查询</button>
        </div>
    </form>
    <div class="today w shadow">
        <span style="font-size:20px">北京 </span>&nbsp;&nbsp;
        晴 &nbsp;&nbsp;
        33℃ &nbsp;&nbsp;
        东风 1-3级
    </div>
    <div class="list w">
        <!-- <div class="col">
            <div class="title">2025-06-17（星期二）</div>
            <div><img src="imgs/day.png">天气：晴</div>
            <div><img src="imgs/day.png">温度：33℃</div>
            <div><img src="imgs/day.png">风向(风力)：东风 ( 1-3 )</div>
            <div><img src="imgs/night-black.png">天气：晴</div>
            <div><img src="imgs/night-black.png">温度：21℃</div>
            <div><img src="imgs/night-black.png">风向(风力)：东北风( 1-3 )</div>
        </div>
        -->
    </div>
    <script src="./axios.min.js"></script>
    <script>
        var form = document.querySelector('.form')
        var input = document.querySelector('.form input')
        var list = document.querySelector('.list')
        form.onsubmit = function (e) {
            // 阻止事件默认行为
            e.preventDefault()
            // 获取用户输入的城市名称
            var city = input.value.trim()
            if (!city) {
                return alert('请输入城市名称')
            }
            axios({
                // ?app_id=spmcjmi2pqeqqjdr&app_secret=yqSEX3rrUg5Q1xVrGb5LsMLSPPqOTN3J
                url: `https://www.mxnzp.com/api/weather/forecast/${city}`,
                params: {
                    // 应用id
                    app_id: 'spmcjmi2pqeqqjdr',
                    // 应用密钥
                    app_secret: 'yqSEX3rrUg5Q1xVrGb5LsMLSPPqOTN3J'
                }
            }).then(res => {
                console.log(res.data);
                var html = ''
                res.data.data.forecasts.forEach(item => {
                    html += `
                        <div class="col">
                            <div class="title">${item.date}（星期五）</div>
                            <div><img src="imgs/day.png">天气：${item.dayWeather}</div>
                            <div><img src="imgs/day.png">温度：${item.dayTemp}</div>
                            <div><img src="imgs/day.png">风向(风力)：${item.dayWindDirection} ( ${item.dayWindPower} )</div>
                            <div><img src="imgs/night-black.png">天气：${item.nightWeather}</div>
                            <div><img src="imgs/night-black.png">温度：${item.nightTemp}</div>
                            <div><img src="imgs/night-black.png">风向(风力)：${item.nightWindDirection} (${item.nightWindPower})</div>
                        </div>
                    `
                })
                list.innerHTML = html
            })

        }
    </script>


</body>

</html>